package com.apes.scm.rbac.model;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * 功能：本地组织权限
 *
 * @author xul
 * @create 2017-12-15 13:44
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = LocalPermitItem.CONST_TABLE_NAME, indexes = {@Index(name = "i_local_permit_item_org", columnList = "org_id, type, purpose")})
public class LocalPermitItem extends BaseModel {
    public static final String CONST_TABLE_NAME = "aut_local_permit_item";

    @Id
    @Column(name = "id", length = 32)
    @GenericGenerator(name = "id-generator", strategy = "uuid")
    @GeneratedValue(generator = "id-generator")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "本地权限明细")
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "type", referencedColumnName = "id")
    private Enumeration type; //公司、部门、仓库、网点、供应商、......

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "purpose", referencedColumnName = "id")
    private Enumeration  purpose; //所属、操作、查询、......

    @Column(name = "org_id", length = 32, nullable = false)
    private String orgId;  //组织代码

    @Column(name = "org_name", length = 150, nullable = false)
    private String orgName;

    @ManyToOne(optional = false)
    @JoinColumn(name = "local_permit_id", referencedColumnName = "id", nullable = false)
    private LocalPermit localPermit;

}
